<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.houduan.model.Computer" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>编辑电脑 - 网吧管理系统</title>
    <ul class="topbar-right">
        <li class="dropdown dropdown-profile">
            <a href="javascript:void(0)" data-toggle="dropdown">
                <img class="img-avatar img-avatar-48 m-r-10" src="images/users/avatar.jpg" alt="用户头像" />
                <span>管理员 <span class="caret"></span></span>
            </a>
            <ul class="dropdown-menu dropdown-menu-right">
                <li><a href="profile.jsp"><i class="mdi mdi-account"></i> 个人信息</a></li>
                <li><a href="change_password.jsp"><i class="mdi mdi-lock-outline"></i> 修改密码</a></li>
                <li><a href="logout.jsp"><i class="mdi mdi-logout-variant"></i> 退出登录</a></li>
            </ul>
        </li>
    </ul>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-5">
    <h2>编辑电脑</h2>
    <hr>
    <%
        // 获取 Computer 对象
        Computer computer = (Computer) request.getAttribute("computer");
        if (computer == null) {
    %>
    <div class="alert alert-danger">
        <strong>错误！</strong> 未找到相关电脑信息。
    </div>
    <a href="ComputerServlet?action=list" class="btn btn-secondary">返回电脑列表</a>
    <%
    } else {
    %>
    <form method="post" action="ComputerServlet?action=update">
        <input type="hidden" name="id" value="<%= computer.getId() %>">
        <div class="form-group">
            <label for="name">名称</label>
            <input type="text" class="form-control" id="name" name="name" value="<%= computer.getName() %>" required>
        </div>
        <div class="form-group">
            <label for="type">型号</label>
            <input type="text" class="form-control" id="type" name="type" value="<%= computer.getType() %>" required>
        </div>
        <div class="form-group">
            <label for="status">状态</label>
            <select class="form-control" id="status" name="status" required>
                <option value="空闲" <%= "空闲".equals(computer.getStatus()) ? "selected" : "" %>>空闲</option>
                <option value="使用中" <%= "使用中".equals(computer.getStatus()) ? "selected" : "" %>>使用中</option>
                <option value="维护中" <%= "维护中".equals(computer.getStatus()) ? "selected" : "" %>>维护中</option>
            </select>
        </div>
        <div class="form-group">
            <label for="price">价格（每小时）</label>
            <input type="number" step="0.01" class="form-control" id="price" name="price" value="<%= computer.getPrice() %>" required>
        </div>
        <div class="form-group">
            <label for="description">描述</label>
            <textarea class="form-control" id="description" name="description"><%= computer.getDescription() %></textarea>
        </div>
        <button type="submit" class="btn btn-primary">保存</button>
        <a href="ComputerServlet?action=list" class="btn btn-secondary">取消</a>
    </form>
    <%
        }
    %>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.min.js"></script>
</body>
</html>
